#docker build --no-cache -t php-fpm:8.0.7.1 .

FROM php:7.4.27-fpm
MAINTAINER chenzhiwei "chenzhiweiwk@qq.com"

# set timezone
ENV TZ=Asia/Shanghai

# set timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
    && sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
    && apt-get update && apt-get install -y \
       libfreetype6-dev \
       libjpeg62-turbo-dev \
       libpng-dev \
       libzip-dev \
       libcurl4-openssl-dev \
       libxml2-dev \
       libldap2-dev \
       vim \
       git \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install zip \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install opcache \
    && docker-php-ext-install mysqli \
    && docker-php-ext-install curl \
    && docker-php-ext-install sockets \
    && docker-php-ext-install ldap \
    && docker-php-ext-install soap \
    && docker-php-ext-install xmlrpc \
    && apt-get update && apt-get install -y procps wget libpcre3-dev zlib1g-dev openssl libssl-dev \
    && cd /tmp \
    && wget http://nginx.org/download/nginx-1.20.1.tar.gz \
    && tar -zxf nginx-1.20.1.tar.gz \
    && cd nginx-1.20.1 \
    && mkdir -p /var/tmp/nginx/client/ \
    && mkdir -p /var/tmp/nginx/proxy/ \
    && mkdir -p /var/tmp/nginx/fcgi/ \
    && mkdir -p /var/tmp/nginx/scgi/ \
    && mkdir -p /var/tmp/nginx/scgi/ \
    && useradd -s /sbin/nologin -M nginx \
    && ./configure \
         --prefix=/usr/local/ \
         --sbin-path=/usr/sbin/ \
         --conf-path=/usr/local/nginx/nginx.conf \
         --error-log-path=/usr/local/nginx/log/error.log \
         --http-log-path=/usr/local/nginx/log/access.log \
         --pid-path=/var/run/nginx/nginx.pid  \
         --lock-path=/var/lock/nginx.lock \
         --user=nginx \
         --group=nginx \
         --with-http_ssl_module \
         --with-http_flv_module \
         --with-http_stub_status_module \
         --with-http_gzip_static_module \
         --http-client-body-temp-path=/var/tmp/nginx/client/ \
         --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
         --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
         --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
         --http-scgi-temp-path=/var/tmp/nginx/scgi \
         --with-pcre \
    && make install \
    && rm /tmp/nginx-1.20.1.tar.gz \
    && rm -rf /tmp/nginx-1.20.1 \ 
    && mkdir /usr/local/nginx/vhosts \ 
    && mkdir /usr/local/nginx/certs

COPY nginx.conf /usr/local/nginx/nginx.conf
COPY yii.conf /usr/local/nginx/vhosts/yii.conf
COPY startup.sh /srv/startup.sh
COPY composer /usr/local/bin/composer


# clear the apt list
RUN rm -r /var/lib/apt/lists/* \
  && chmod 777 /srv/startup.sh \
  && cd /var/www/html \
  && git clone -b 2.0.43.1.1 https://gitee.com/lv_frame/yii.git yii \
  && chown www-data:www-data -R yii 

WORKDIR /var/www/html

# start php-fpm and nginx
ENTRYPOINT ["/bin/bash", "-C", "/srv/startup.sh"]
